/*
 * @Author: DUST
 * @Date: 2023-11-24 16:48:37
 * @LastEditors: DUST
 * @LastEditTime: 2023-11-28 11:30:35
 * @FilePath: \business-card-system\server\app\service\BusinessCardUserService.ts
 * @Description:
 * undefined
 */

import BusinessCardUser from "../model/BusinessCardUser";
import { BusinessCArdUserItem } from "../validator/BusinessCardUserValidator";

class BusinessCardUserService {
  /**
   * @description: 新增一个名片人员
   * @param {any} value:要新增的字段
   */
  addBusinessCardUser(value: any) {
    console.log("新增内容：", value);
    return BusinessCardUser.findOrCreate({
      where: {
        mobile: value.mobile,
      },
      defaults: value
    });
  }
  /**
   * @description: 编辑对应ID的名片人员信息
   * @param {noteItem} values：需要修改的字段
   * @param {number} id：需要修改的笔记ID
   */
  editBusinessCardUser(values: BusinessCArdUserItem, id: number) {
    return BusinessCardUser.update(values, {
      where: { id },
    });
  }
  /**
   * @description: 查询笔记列表，分页数据
   * @param {number} pageSize：每页最大数据
   * @param {number} pageNumber：当前页码
   */
  getBusinessCardUserListByPage(pageSize: number, pageNumber: number) {
    return BusinessCardUser.findAndCountAll({
      raw: true,
      limit: pageSize,
      offset: (pageNumber - 1) * pageSize,
      order: [["createTime", "DESC"]],
    });
  }
  /**
   * @description: 查询指定人员信息
   * @param {number} id: 人员信息ID
   */
  getBusinessCardUserById(id: number) {
    return BusinessCardUser.findByPk(id);
  }
  /**
   * @description: 删除笔记
   * @param {number} id：需要删除的笔记的ID
   */
  deleteBusinessCardUser(id: number) {
    return BusinessCardUser.destroy({
      where: { id },
    });
  }
}

export default new BusinessCardUserService();
